package cn.jari.erp.inventory.controllers.base;

import cn.jari.erp.Roles;
import cn.jari.erp.inventory.api.InventoryItemService;
import cn.jari.erp.inventory.dto.DeleteInventoryItemCommand;
import javax.validation.constraints.NotNull;
import cn.jari.erp.inventory.dto.UpdateInventoryItemCommand;
import cn.jari.erp.inventory.dto.InventoryItemDto;
import cn.jari.erp.inventory.dto.CreateInventoryItemCommand;
import com.csicit.ace.api.annotations.OkMessage;
import com.csicit.ace.utils.ApplicationContextUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/*
 * 警告：代码由鲲舟平台生成，请勿手动修改。
 * Warn: This class file is generated by JARI-ACE platform, please do not modify manually。
 */

/**
 * InventoryItem控制器基类
 */
@RequiredArgsConstructor
public abstract class AbstractInventoryItemController {
    private InventoryItemService inventoryItemService() {
        return ApplicationContextUtil.getBean(InventoryItemService.class);
    }

    /**
     * 创建存货档案
     *
     * @param command 创建命令参数{@link CreateInventoryItemCommand}
     * @return {@link InventoryItemDto}
     */
    @Operation(summary = "创建存货档案")
    @PostMapping(path = "")
    @PreAuthorize("hasRole('" + Roles.INVENTORY_MANAGE + "')")
    InventoryItemDto createInventoryItem(
        @RequestBody
        @Validated
        @Parameter(description = "创建命令参数")
        @NotNull(message = "{error.common.isNull}")
        CreateInventoryItemCommand command
    ) {
        return doCreateInventoryItem(command);
    }

    protected InventoryItemDto doCreateInventoryItem(CreateInventoryItemCommand command){
        return inventoryItemService().createInventoryItem(command);
    }
    /**
     * 修改存货档案
     *
     * @param command 修改命令参数{@link UpdateInventoryItemCommand}
     * @return {@link InventoryItemDto}
     */
    @Operation(summary = "修改存货档案")
    @PutMapping(path = "")
    @PreAuthorize("hasRole('" + Roles.INVENTORY_MANAGE + "')")
    InventoryItemDto updateInventoryItem(
        @RequestBody
        @Validated
        @Parameter(description = "修改命令参数")
        @NotNull(message = "{error.common.isNull}")
        UpdateInventoryItemCommand command
    ) {
        return doUpdateInventoryItem(command);
    }

    protected InventoryItemDto doUpdateInventoryItem(UpdateInventoryItemCommand command){
        return inventoryItemService().updateInventoryItem(command);
    }
    /**
     * 创建存货档案
     *
     * @param command 创建命令参数{@link DeleteInventoryItemCommand}
     * @return {@link InventoryItemDto}
     */
    @Operation(summary = "创建存货档案")
    @PostMapping(path = "/delete")
    @PreAuthorize("hasRole('" + Roles.INVENTORY_MANAGE + "')")
    InventoryItemDto deleteInventoryItem(
        @RequestBody
        @Validated
        @Parameter(description = "创建命令参数")
        @NotNull(message = "{error.common.isNull}")
        DeleteInventoryItemCommand command
    ) {
        return doDeleteInventoryItem(command);
    }

    protected InventoryItemDto doDeleteInventoryItem(DeleteInventoryItemCommand command){
        return inventoryItemService().deleteInventoryItem(command);
    }
}
